export function checkOrder(arr) {
  var morningCount = {}; // 上午接单计数器
  var afternoonCount = {}; // 下午接单计数器
  var employeeOrders = {}; // 存储员工订单索引的对象
  var problematicOrders = []; // 错误索引列表

  for (var i = 0; i < arr.length; i++) {
    var order = arr[i];

    // 根据时间确定应该使用的接单计数器
    var count;
    if (order['time'] < '12:00:00') {
      count = morningCount;
    } else {
      count = afternoonCount;
    }

    // 增加员工的接单数量
    if (order['userId'] === undefined || order['userId'] === null || order['userId'] === "") {
      problematicOrders.push(i);
    } else {
      if (count[order['userId']] === undefined) {
        count[order['userId']] = 1;
      } else {
        count[order['userId']]++;
      }

      // 将当前订单索引添加到员工订单索引对象中
      if (!employeeOrders[order['userId']]) {
        employeeOrders[order['userId']] = [];
      }
      employeeOrders[order['userId']].push(i);
    }
  }

  for (var employeeId in employeeOrders) {
    var orders = employeeOrders[employeeId];
    if (morningCount[employeeId] >= 2 || afternoonCount[employeeId] >= 2) {
      problematicOrders = problematicOrders.concat(orders);
    }
  }

  return problematicOrders;
}